﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Fotobanka
{
    public partial class EditovatGalerii : System.Web.UI.Page
    {
        GalleriesManager gm;
        LoginInfo li;
        protected void Page_Load(object sender, EventArgs e)
        {
            gm = new GalleriesManager();
            li = (LoginInfo)Session["logged_user_id"];
        }

        protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            if (e.NewValues["Name"] == null)
            {
                e.Cancel = true;
                errors.Text = "Galerie musí mít jméno";
                
            } else if (gm.GalleryAlreadyExist(e.NewValues["Name"].ToString(), Convert.ToInt32(e.OldValues["GalleryAdminId"].ToString()), Convert.ToInt32(e.OldValues["Id"].ToString()))) {
                e.Cancel = true;
                errors.Text = "Galerie s tímto jménem již existuje";
            }else 
                errors.Text = "";
        }
    }
}
